package com.vlong.town.controller.server.goodsType;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.vlong.town.controller.base.BaseController;
import com.vlong.town.entity.goodsType.GoodsType;
import com.vlong.town.service.goodsType.GoodsTypeService;

@RestController
@RequestMapping("/rest/goodsType")
public class GoodsTypeRestController extends BaseController{

	@Autowired
	private  GoodsTypeService  goodsTypeService;//分类业务接口
	
	/*
	 * 查询父级分类
	 */
	@GetMapping("/rootGoodsTypeList")
	public  List<GoodsType>   rootlist(){
		List<GoodsType> queryList = goodsTypeService.queryList(null, null, 0L, 1, null, 1, 0, 1, null, null, null);
		return  queryList;
	}
	
	/*
	 * 查询子级分类
	 */
	@RequestMapping("/subGoodsTypeList/{typePid}")
	public  JSONObject   sublist(@PathVariable(required=true, value="typePid") String typePid){
		List<GoodsType> queryList = goodsTypeService.queryList(null, null, Long.parseLong(typePid), 1, null, 2, 0, null, null, null, null);
		JSONObject  jsonObject=new  JSONObject();
		JSONArray  jsonArray=new JSONArray();
		for (GoodsType goodsType : queryList) {
			List<GoodsType> queryList2 = goodsTypeService.queryList(null, null, goodsType.getTypeId(), 1, null, 3, 0, null, null, null, null);
			for (GoodsType goodsType2 : queryList2) {
				jsonArray.add(goodsType2.getTypeName());
			}
			jsonObject.put(goodsType.getTypeName(), jsonArray);
		}
		return  jsonObject;
	}
	
	
	
}
